package com.changli01.use.exer1;

import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        TreeSet<Employee> em = new TreeSet<>();
        Employee e1 = new Employee("sail",21,new MyDate(2005,9,12));
        Employee e2 = new Employee("Ksla",20,new MyDate(2005,3,9));
        Employee e3 = new Employee("Jerry",35,new MyDate(1989,2,12));
        Employee e4 = new Employee("Tom",50,new MyDate(1974,4,27));
        Employee e5 = new Employee("Linda",54,new MyDate(1970,10,28));
        em.add(e1);
        em.add(e2);
        em.add(e3);
        em.add(e4);
        em.add(e5);
//        for (Employee e : em) {
//            System.out.println(e);
//        }
        TreeSet<Employee> em1 = new TreeSet<>(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                int value1 = o1.getBirthday().getYear() - o2.getBirthday().getYear();
                if(value1 == 0){
                    int value2 = o1.getBirthday().getMonth() - o2.getBirthday().getMonth();
                    if(value2 == 0){
                        return o1.getBirthday().getDay() - o2.getBirthday().getDay();
                    }
                    else return value2;
                }
                return value1;
            }
        });
        em1.add(e1);
        em1.add(e2);
        em1.add(e3);
        em1.add(e4);
        em1.add(e5);
        for (Employee e : em1) {
            System.out.println(e);
        }

    }
}
